package com.example.xd.DAO;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.xd.Entity.User;
import com.example.xd.Entity.Video;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;


@Mapper
public interface userMapper extends BaseMapper<User> {

 //创建用户
 @Insert("""
        insert into user(user_name,user_email,user_password,user_image,user_register_time,user_nickname,user_points)values (#{name},#{email},#{password},#{imageUrl},#{registerTime},"请设置昵称",0)""")
 @Results({@Result(property = "name",column = "user_name"),
         @Result(property = "email",column = "user_email"),
         @Result(property = "password",column = "user_password"),
         @Result(property = "registerTime",column = "user_register_time"),

 })
 void InsertUser(User user);

 //返回用户id
 @Select("""
 select user_id from user where user_email = #{user_email}""")
 int SelectUserIdByEmail(String user_email);

 //查找是否存在同名
  @Select("""
  select count(*) from user where user_name=#{user_name}""")
 int selectUserName(@Param("user_name")String user_name);

  //登录事件处理
 @Select("""
select * from user where user_email=#{user_email} and user_password=#{user_password}""")
 @Results({
         @Result(property = "email",column = "user_email"),
         @Result(property = "password",column = "user_password")
 })
 User selectUser(@Param("user_email")String user_email, @Param("user_password")String user_password);

 //调取头像
 @Select("""
select user_image from user where user_email=#{user_email}""")
 @Results({@Result(property = "imageUrl",column = "user_image")})
 String selectUserImage(@Param("user_email")String user_email);

 //通过email查找id
 @Select("""
select user_id from user where user_email=#{user_email}""")
 @Result(property = "id",column = "user_id")
 int selectUserID(@Param("user_email")String user_email);

 //检查视频名称是否重复
 @Select("""
select count(*) from video where video_name=#{video_name}""")
 int selectVideoName(@Param("video_name")String video_name);

 //用户上传视频
 @Insert("""
insert into video(video_name,video_description,video_duration,video_publisher_id,video_upload_time,video_thumbnail,video_category,video_url) values (#{name},#{description},#{duration},#{UserId},#{UploadTime},#{thumbUrl},#{category},#{videoUrl})""")
 void InsertVideo(Video video);

}
